package com.yannuo.util;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class LoggingInterceptor implements MethodInterceptor {

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        //前置增强
        System.out.println("日志开始执行："+method.getName());

        //原始方法
        Object result = method.invoke(o, objects);

        //后置增强
        System.out.println("CGLIB日志执行完成："+method.getName());
        return result;
    }
}
